package 多线程.内存可见性;

import java.util.Scanner;

public class Main {
    //private static int count = 0;
    private  volatile static int count = 0;//告诉编译器这个变量是反复无常的 就可以避免内存可见性问题

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
           while(count == 0){

           }
            System.out.println("t1结束了");
        });

        Thread t2 = new Thread(() -> {
           Scanner sc = new Scanner(System.in);
            System.out.println("输入一个数");
            count = sc.nextInt();
        });
        t1.start();
        t2.start();

    }
}
